//房源panal
var gridStore = null;
var gridStore2 = null;
var gridStore3 = null;
var gridStore4 = null;
var houseTypeIdStore = null;
var premisesIdStore = null;
var rqTheirMotivesStore = null;
var rqFocusIdStore = null;
var rqServicesIdStore = null;
var ftContactWayStore = null;
//var ftContactWay1 = "";
var congshihangyeStore = null;
var roomIdStore = null;
var flagGiveUp = false;
var DCouple = "";
/**	自动判断客户等级需求
var CCouple = DCouple.concat("rqTheirMotives,rqFocusId,rqDemandArea,rqPaymentMethod,rqServicesId,peResidenceProvinceId,peWorkaroundProvinceId,congshihangye");
**/
var CCouple = DCouple.concat("" );
var BCouple = CCouple.concat("" );
var ACouple = BCouple.concat("rqTheirMotives,rqFocusId,rqDemandArea,rqPaymentMethod,rqServicesId,peResidenceProvinceId,peWorkaroundProvinceId,congshihangye");
var levels = ['','A','B','C','D'];
var ALLCouple = [];
function storeMethed(result){
	return new Ext.data.Store({
    	autoDestroy: true,
        fields :["des","no"],
        data : result
	});
}

function userOption(type){
	//var yxfy = Ext.getCmp("fangyuanGridPanel");
    //yxfy.setTitle( yxfy.title.replace("<font style='color:#e90000;'>*</font>",""));
	if(ALLCouple.length!=0){
		for(var i=0;i<ALLCouple.length;i++){
			var allcObj = Ext.getCmp(ALLCouple[i]);
    		allcObj.setFieldLabel(allcObj.fieldLabel.replace("<font style='color:#e90000;'>*</font>",""));
			allcObj.blankText='';
		}
	}
	
	//清楚掉上一次的，保存这一次的.
	ALLCouple = new Array();
	//AJAX加载数据,不让页面加载JS时间过长，导致页面卡死
	var text=[];
	if(type=="2"){
		//yxfy.setTitle("<font style='color:#e90000;'>*</font>" + yxfy.title);
		text=ACouple.split(",");
	}else{
		return false;
	}
	for(var i=0;i<text.length;i++){
    	var ajObj = Ext.getCmp(text[i]);
		ajObj.setFieldLabel("<font style='color:#e90000;'>*</font>"+ajObj.fieldLabel);
		ALLCouple.push(text[i]);
    }
}

//根据客户等级验证 客户信息填写情况
function notBlank(ids){
	if(ids == ""){
		return true;
	}
    var text = ids.split(",");
    for(var i = 0;i < text.length;i++){
        if(Ext.getCmp(text[i]) == null) return false;
        if(Ext.getCmp(text[i]).getValue() == '' || Ext.getCmp(text[i]).getValue() == null){
            return false;
        }
    }
    return true;
}
function realLevel(){
    var type = Ext.getCmp("customerStar").getValue();
	var level = 5;
    // 未选择意向等级
    if(notBlank(DCouple)) level = 5;
    //if(notBlank(ACouple) &&  gridStore4.getCount()) level = 2;
    if(notBlank(ACouple)) level = 2;
    return level;
}
function validUserLevel(){
    var ids = '';
    var type = Ext.getCmp("customerStar").getValue();
    //var type = realLevel();
    switch(type){
        case "5" :
            ids = DCouple;
            break;
        case "4" :
            ids = CCouple;
            break;
        case "3" :
            ids = BCouple;
            break;
        case "2" :
            ids = ACouple;
            break;
        default:// 未选择意向等级
            return -2
    }
    /* 20180410需求 —— 意向房源可以为空  */
    /*if(type == '1' || type == '2'){
    	console.log(gridStore4.getCount());
        var records4=gridStore4.getCount();
        if(records4 <= 0){
        	return -1;//验证不通过
		}
	}*/
    if(notBlank(ids)){
        type = 0
    }else{
        type = -1;
    }
    return type;
}


//是否存在认领
function giveUpCustomer(projectId,customerPhone){
	if(customerPhone!=null&&customerPhone!=""){
		//是否存在认领
		var params = {
		    		projectId:projectId,
		    		customerPhone:customerPhone,
		    		page:1,
		    		limit:10,
		};
		Ext.Ajax.request({
	  			 url: contextPath+"/customer/giveUp/giveUpList",
	               params: params,
	               method: 'POST',
	               callback: function (options, success, response) {
		                	 var obj = JSON.parse(response.responseText);
		                	 if(obj.rows!=null&&obj.rows.length>=0){
		                		flagGiveUp = true;
		                		Ext.Msg.confirm('温馨提示', '该客户为已放弃客户，是否认领?', function(btn, text){
	  						    if (btn == 'yes'){
	  						    	var selectWindow=Ext.create('component.giveCustomer.selectWindow',{
				           		 			callbackFun: function (record) {
				           		 				var result=Ext.JSON.decode(record);
				           		 				Ext.Ajax.request({
	  	  			           		 			url: contextPath+"/customer/giveUp/getGiveUpCustomer",
		  	        			                params: {customerId:result.id},
		  	        			                method: 'POST',
		  	        			                callback: function (options, success, response) {
		  	        			                	var obj = JSON.parse(response.responseText);
		  	        			                	if(obj.res==1){
		  	        			                		Ext.MessageBox.alert('提示', '认领成功!');
		  	        			                	    setTimeout(function(){
		  	        			                	    	 parent.openMenu('0','menu_0006_0001','menu_0006','客户列表','/customer/customer/index');
		  	        			                	    	 var tabKey = "customer_"+defaultProjectId;
			  	        						        	 parent.TabControlRemove(tabKey);
		  	        			                	    }, 2000);
		  	        			                		
		  	        			                	}else{
		  	        			                		Ext.MessageBox.alert('提示', obj.resMsg);
		  	        			                	}
		  	        			                }
				           		 				});
				           		 	        },
				           		 	        resourcesCode:'menu_0006_0020',
				           		 	        projectId:obj.rows[0].projectId,
				           		 	        customerPhone:obj.rows[0].customerPhone,
				           		 	        giveUpStatus:'1'
				           		 	        
				           		 	     });
			           		 	    	 selectWindow.show();
	  						    }
	  						});
	              	 }else{
	              		flagGiveUp = false;
	              	 }
	             }

		});
	}
}


//增加客户信息的ajax请求
function add(params,resultJson,resultJson2,resultJson3,resultJson4){
	  Ext.getCmp("customerSubmitBtn").setVisible(false);
    Ext.Ajax.request({
        url: contextPath+'/customer/customer/add?gridJson='+resultJson+'&gridJson2='+resultJson2+'&gridJson3='+resultJson3+'&gridJson4='+resultJson4,
		params:params,
        callback: function (options, success, response) {
            if (success) {
                var obj = JSON.parse(response.responseText);
                if(obj.res=="1"){
                    Ext.MessageBox.alert("系统提示","保存成功");
                    setTimeout(function(){
                        location.href=contextPath+'/customer/customer/index?menu=menu_0006_0001';
                    }, 2000)
                }else if(obj.res=="100"){
                	Ext.getCmp("customerSubmitBtn").setVisible(true);
                	var customerPhone =  Ext.getCmp("customerPhone").getValue();
                	var projectId = Ext.getCmp('cbstore').getValue();
                    giveUpCustomer(projectId, customerPhone)
                }else if(obj.res=="99"){
                	Ext.getCmp("customerSubmitBtn").setVisible(true);
                    Ext.MessageBox.alert("系统提示","客户已经存在!");
                }else{
                	Ext.getCmp("customerSubmitBtn").setVisible(true);
                    Ext.MessageBox.alert("系统提示",obj.resMsg);
                }
            }else{
                Ext.getCmp("customerSubmitBtn").setVisible(true);
                Ext.MessageBox.alert("系统提示","系统异常!");
            }
        }

    });
}

Ext.onReady(function() {
	Ext.QuickTips.init(); //为组件提供提示信息功能，form的主要提示信息就是客户端验证的错误信息。
	Ext.form.Field.prototype.msgTarget='side'; //提示的方式，枚举值为: 
	houseTypeIdStore = new Ext.data.Store({
        fields: ["houseTypeName", "id"],
        proxy:{
            type:'ajax',
            url:contextPath+'/customer/customer/projectHouseTypeList',
            reader:{
                type: 'json', 
                root: 'root'  //数据
           }
        },
		autoLoad:false
    });
	premisesIdStore = new Ext.data.Store({
        fields: ["groupName", "id"],
        proxy:{
            type:'ajax',
            url:contextPath+'/customer/customer/projectPremisesList',
            reader:{
                type: 'json', 
                root: 'root'  //数据
           }
        },
		autoLoad:false
    });
	roomIdStore = new Ext.data.Store({
        fields: ["combinedName", "id"],
        proxy:{
            type:'ajax',
            url:contextPath+'/customer/customer/projectRoomList',
            reader:{
                type: 'json', 
                root: 'root'  //数据
           }
        },
		autoLoad:false
    });
	 gridStore = Ext.create('Ext.data.Store', {
	    fields: ["memberName","documentType","documentNumber"],
	    //是否在服务端排序 （true的话，在客户端就不能排序）
	    remoteSort: false,
	    proxy: {
	        type: 'ajax',
	        url: contextPath+'/customer/familyMember/findList',
	        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
	            type: 'json', //返回数据类型为json格式
	            root: 'obj'
	        },
	        actionMethods: {read: 'POST'}
	    }
	});
	gridStore2 = Ext.create('Ext.data.Store', {
	    fields: ["memberName","documentType","documentNumber"],
	    //是否在服务端排序 （true的话，在客户端就不能排序）
	    remoteSort: false,
	    proxy: {
	        type: 'ajax',
	        url: contextPath+'/customer/familyMember/findList',
	        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
	            type: 'json', //返回数据类型为json格式
	            root: 'obj'
	        },
	        actionMethods: {read: 'POST'}
	    }
	});
	gridStore3 = Ext.create('Ext.data.Store', {
	    fields: ["memberName","documentType","documentNumber"],
	    //是否在服务端排序 （true的话，在客户端就不能排序）
	    remoteSort: false,
	    proxy: {
	        type: 'ajax',
	        url: contextPath+'/customer/familyMember/findList',
	        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
	            type: 'json', //返回数据类型为json格式
	            root: 'obj'
	        },
	        actionMethods: {read: 'POST'}
	    }
	});
	gridStore4 = Ext.create('Ext.data.Store', {
		id:'fangyuanGridStore',
	    fields: ["memberName","documentType","documentNumber"],
	    //是否在服务端排序 （true的话，在客户端就不能排序）
	    remoteSort: false,
	    proxy: {
	        type: 'ajax',
	        url: contextPath+'/customer/familyMember/findList',
	        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
	            type: 'json', //返回数据类型为json格式
	            root: 'obj'
	        },
	        actionMethods: {read: 'POST'}
	    }
	});
});

Ext.define('customer.payDeposit.add.estatePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var sexStoreList = [
            {"value":"1","text":"男"},
            {"value":"2","text":"女"}
        ];
		var sexStore = Ext.data.Store({
	    	autoDestroy: true,
	        fields :["value","text"],
	        data : sexStoreList
		});
		informedWayStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "codeName"],
	        proxy:{
	            type:'ajax',
	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	            reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
	        },
	        autoLoad:false
	    });
		
		var recommendedCategoryStoreList = [
            {"value":"1","text":"分销/中介"},
            {"value":"2","text":"老客户(未成交客户)"},
            {"value":"3","text":"老业主"}
        ];

		var recommendedCategoryStore = Ext.data.Store({
	    	autoDestroy: true,
	        fields :["value","text"],
	        data : recommendedCategoryStoreList
		});
		
		var intentionLevelStoreList = [
             {"value":"2","text":"A"},
             {"value":"3","text":"B"},
             {"value":"4","text":"C"},
             {"value":"5","text":"D"}
         ];
		var intentionLevelStore = Ext.data.Store({
	    	autoDestroy: true,
	        fields :["value","text"],
	        data : intentionLevelStoreList
		});
		
		var customerStatusStoreList = [
           {"value":"1","text":"问询"},
           {"value":"2","text":"来访"},
           {"value":"6","text":"无意向"}
        ];
		var customerStatusStore = Ext.data.Store({
	    	autoDestroy: true,
	        fields :["value","text"],
	        data : customerStatusStoreList
		});
		
		customerOriginStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "codeName"],
	        proxy:{
	            type:'ajax',
	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	            reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
	        },
	        autoLoad:false
	    });
		
		var me=this;
		var row_1={
			xtype: "container",
			fieldDefaults: {
	            labelAlign: 'top',
	            msgTarget: 'side'
		    },
		    defaults: {
	            border: false,
	            xtype: 'panel',
	            flex: 1,
	            layout: 'anchor'
		    },
            layout: "hbox",
            items:[{
                   	minWidth: 200,
					xtype:'displayfield',
					fieldLabel:'经纪人',
	                renderer:function(val){
	                	return userName;
	                }
				},{
					minWidth: 200,
					xtype:'displayfield',
			    	fieldLabel:'创建人',
	                renderer:function(val){
	                	return userName;
	                }
				}
			]
	    };
		var row_2={
			id:"isPaydepositTrue",
			fieldDefaults: {
		            labelAlign: 'top',
		            msgTarget: 'side'
		    },
		    defaults: {
		            border: false,
		            xtype: 'panel',
		            flex: 1,
		            layout: 'anchor'
		    },
		    border: false,
				layout: 'hbox',items: [{
		            items: [{
			            xtype:'combobox',  
			            id:'cbstore',  
			            store: cbstore,
			            displayField: "projectName",           
			            valueField: "id",  
			            fieldLabel:'<font style="color:#e90000;">*</font>项目名称',
			            width:300,
			            queryMode:'local',
			            typeAhead: true,  
		    			name:'projectId',
			            listeners:{
			            	'change':function(value){
			            		var customerPhone =  Ext.getCmp("customerPhone").getValue();
			            		if(customerPhone!=null&&customerPhone!=""){
			            			giveUpCustomer(value.lastValue,customerPhone);
			            		}
			            		
			            		houseTypeIdStore.load({
			            			params:{
			            				'projectId':value.lastValue
			            			}
				            	});
			            		premisesIdStore.load({
			            			params:{
			            				'projectId':value.lastValue
			            			}
			            		});
			            		/*roomIdStore.load({
			            			params:{
			            				'projectId':value.lastValue
			            			}
			            		});*/
			            		projectId=value.lastValue;
			            		if(projectId && projectId == "-1"){
				            		projectId="";
				            		Ext.getCmp("cbstore").setValue("");
			            		}
			            		if(projectId != ""){
			            			//获知途径
                                    Ext.getCmp('informedWay').setValue("");
			            			informedWayStore.load({
				            			params:{
				            				'projectId':projectId,
				            				'typeValue':'informedWay'
				            			}
				            		});
			            			//客户性质
                                    /*Ext.getCmp('customerOrigin').setValue("");
			            			customerOriginStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'customerNature'
				            			}
			            			});*/
			            			//置业动机
                                    Ext.getCmp('rqTheirMotives').setValue("");
			            			rqTheirMotivesStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'theirMotives'
				            			}
			            			});
			            			//关注重点
                                    Ext.getCmp('rqFocusId').setValue("");
			            			rqFocusIdStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'focus'
				            			}
			            			});
			            			//生活服务
                                    Ext.getCmp('rqServicesId').setValue("");
			            			rqServicesIdStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'lifeService'
				            			}
			            			});
			            			//接触方式
			            			Ext.getCmp('ftContactWay').setValue("");
			            			ftContactWayStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'contactWay'
				            			},
				            			callback: function(records, options, success){
				            				//去掉“电转访”
                                            for(var i = 0; i < records.length; i++){
                                            	if(records[i].get('codeName')  == "电转访"){
                                            		ftContactWayStore.remove(ftContactWayStore.getAt(i));
                                            	}
                                            }
                                        }
			            			});
			            			//从事行业
                                    Ext.getCmp('congshihangye').setValue("");
			            			congshihangyeStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'congshihangye'
				            			}
			            			});
			            		}
			            	}
			            },
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false
	            	},{
		                xtype:'textfield',
		                fieldLabel: '<font style="color:#e90000;">*</font>客户姓名',
						//fieldLabel: '客户姓名',
		                name: 'customerName',
		                allowBlank:true,
		                blankText:'不能为空',
						id:'customerName'
		            }, {
			            xtype:'combobox',  
//			            style: 'position:absolute;left:15px;',  
			            id:'customerSex',  
			            store: sexStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'<font style="color:#e90000;">*</font>性别',
			            //fieldLabel:'性别',
			            typeAhead: true,
		    			name:'customerSex',
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false
		            },{
		                xtype:'textfield',
		                fieldLabel: '推荐人姓名',
		                name: 'recommendedName',
		                id: 'recommendedName',
		                hidden:true
		            }, {
		                xtype:'textfield',
		                fieldLabel: '推荐人单位',
		                name: 'recommendedUnit',
		                id: 'recommendedUnit',
		                hidden:true
		            }]
		        }, {
		            items: [{
			            xtype:'combobox',  
			            id:'customerStar',  
			            store: intentionLevelStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'<font style="color:#e90000;">*</font>意向等级',
			            //fieldLabel:'意向等级',
			            typeAhead: true,
		    			name:'intentionLevel',
		                allowBlank:true,
		                blankText:'不能为空',
		                listeners:{
			            	'change':function(value){
//			            		if(value.lastValue=="2"){
//			            			userOption('2');
//			            		}else if(value.lastValue=="3"){
//			            			userOption('3');
//			            		}else if(value.lastValue=="4"){
//			            			userOption('4');
//			            		}else if(value.lastValue=="5"){
//			            			userOption('5');
//			            		}
			            		userOption(value.lastValue);
			            	}
/**		                自动判断客户等级需求
			            	},
		                	afterRender: function(combo) {
		                		//默认选择D等级
		                      　　				combo.setValue("5");
		                    }  
**/		                    
			            },
		                typeAhead:false, 
		                editable:false
		            }
		            /*,{
			            xtype:'combobox',  
			            id:'customerStatus',  
			            store: customerStatusStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'<font style="color:#e90000;">*</font>客户状态',
			            //fieldLabel:'客户状态',
			            typeAhead: true,
		    			name:'customerStatus',
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false
*//**		                自动判断客户等级需求
		                editable:false,
		                listeners :{  
		                	afterRender: function(combo) {
		                		//默认选择第一个选项
		                      　　				var firstValue = customerStatusStore.data[0].value;
		                      　　				combo.setValue(firstValue);
		                    }  
		                }
**//*
		            },{
			            xtype:'combobox',  
			            id:'customerOrigin',  
			            store: customerOriginStore,
			            displayField: "codeName",           
			            valueField: "id",  
						//fieldLabel:'客户性质',
			            fieldLabel:'<font style="color:#e90000;">*</font>客户性质',
		    			name:'customerOrigin',
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }*/,{
			            xtype:'combobox',  
		                fieldLabel: '<font style="color:#e90000;">*</font>获知途径',
		                //fieldLabel: '获知途径',
		                name: 'informedWay',
			            store: informedWayStore,
		                id: 'informedWay',
			            displayField: "codeName",           
			            valueField: "id",
			            listeners:{
			            	'change':function(value){
			            		var displayValue = Ext.getCmp('informedWay').getRawValue();
			            		//为全员营销或者外部推荐时，展示推荐人信息
			            		if(displayValue == "全员营销"|| displayValue == "外部推荐时"){
			            			Ext.getCmp('recommendedCategory').show();
			            			Ext.getCmp('recommendedName').show();
			            			Ext.getCmp('recommendedMobile').show();
			            			Ext.getCmp('recommendedUnit').show();
			            		}else{
			            			Ext.getCmp('recommendedCategory').hide();
			            			Ext.getCmp('recommendedName').hide();
			            			Ext.getCmp('recommendedMobile').hide();
			            			Ext.getCmp('recommendedUnit').hide();
			            		}
			            	}
			            },
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }, {
		                xtype:'numberfield',
		                 fieldLabel: '<font style="color:#e90000;">*</font>联系电话',
		                //fieldLabel: '联系电话',
		                name: 'customerPhone',
		                allowBlank:true,
		                blankText:'不能为空',
		                maxLength:11,  
		                hideTrigger:true,
		                id:'customerPhone',
		                regex: /^1[3|4|5|6|7|8|9]\d{9}$/,
			            listeners:{
			            	blur: function(value){
			            		if(value.lastValue){
			            			//在验证手机号码是否正确
			            			Ext.Ajax.request({
			            				url: contextPath+'/common/mobile/verifyingMobile',
			            				params: {
			            					mobile: value.lastValue,
			            				},
			            				method: 'POST',
			            				async: false,
			            				success: function(response){
			            					var text = Ext.decode(response.responseText);
			            					if(text.result=="1"){
			            						if(text.flag != "1"){
			            							Ext.MessageBox.alert('提示', '请输入正确的手机号码');
			            						}
			            					}
			            				}
			            			});
			            			//判断手机号是否存在
			            			var projectId = Ext.getCmp('cbstore').getValue();
			            			Ext.Ajax.request({
			            				url: contextPath+'/customer/customer/customerPhone',
			            				params: {
			            					phone: value.lastValue,
			            					projectId:projectId
			            				},
			            				method: 'POST',
			            				success: function(response){
			            					var text = Ext.decode(response.responseText);
			            					if(text.res=="1"){
			            						Ext.MessageBox.alert('提示', '该手机号码已存在!');
			            						return false;
			            					}else if(text.res=="10000"){
			            						Ext.MessageBox.alert("系统提示","系统异常!");
			            						return false;
			            					}else{
			            						giveUpCustomer(projectId, value.lastValue);
			            					}
			            				}
			            			});
			            		}
			                }
			            }
		             
		            }, {
			            xtype:'combobox',  
		                fieldLabel: '推荐人类别',
		                id:'recommendedCategory',
		                name: 'recommendedCategory',
			            store: recommendedCategoryStore,
			            displayField: "text",           
			            valueField: "value",
		                hidden:true,
		                typeAhead:false, 
		                editable:false
		            }, {
		                xtype:'numberfield',
		                fieldLabel: '推荐人手机',
		                name: 'recommendedMobile',
		                id:'recommendedMobile',
		                hidden:true,
		                blankText:'不能为空',
		                maxLength:11,  
		                hideTrigger:true,
		                regex: /^1[3|4|5|6|7|8|9]\d{9}$/,
		                listeners:{
			            	blur: function(value){
			            		if(value.lastValue){
			            			//在验证手机号码是否正确
			            			Ext.Ajax.request({
			            				url: contextPath+'/common/mobile/verifyingMobile',
			            				params: {
			            					mobile: value.lastValue,
			            				},
			            				method: 'POST',
			            				async: false,
			            				success: function(response){
			            					var text = Ext.decode(response.responseText);
			            					if(text.result=="1"){
			            						if(text.flag != "1"){
			            							Ext.MessageBox.alert('提示', '请输入正确的手机号码');
			            						}
			            					}
			            				}
			            			});
			            		}
			            	}
		                }
		            },{
		                xtype:'textfield',
		                fieldLabel: 'ID',
		                name: 'id',
		                id:'customerId',
		                hidden:true
		            }]
		        }]
	    };
		var items=[row_1,row_2];
		var initConfigg = {
				title:"客户基本信息",
				bodyStyle: 'padding:5px 5px 0',
		        minHeight: 100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,
		            width:300
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

Ext.define('customer.payDeposit.add.firstjiePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		ftContactWayStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		var row_1={
				fieldDefaults: {
			            labelAlign: 'left',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'column',   
				items: [{
		            items: [{
			            xtype:'combobox',  
			            id:'ftContactWay',  
			            store: ftContactWayStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'<font style="color:#e90000;">*</font>接触方式',
			            typeAhead: true,
		    			name:'ftContactWay',
		                typeAhead:false, 
		                editable:false,
		                allowBlank:true,
			            blankText:'不能为空',
			            queryMode:'local'
		            }, {
		                xtype:'datefield',
		                fieldLabel: '<font style="color:#e90000;">*</font>接触时间',
		                name: 'ftContactTimes',
		                id:'ftContactTimes',
		                format: 'Y-m-d',
		                allowBlank:true,
			            blankText:'不能为空',
			            value: serverDate,
						editable:false,
                        readOnly:true
                    }, {
		                xtype:'textarea',
		                fieldLabel: '<font style="color:#e90000;">*</font>沟通内容',
		                anchor: '80%',
		                name:'ftContactContent',
		                id:'ftContactContent',
		                minWidth:1100,
		                allowBlank:true,
			            blankText:'不能为空'
		            }]
		        }]
	    };
		var items=[row_1];
		var initConfigg = {
		        title:"首次接触信息",
		        minHeight:100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,
		            width:300
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

Ext.define('customer.payDeposit.add.customerPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		rqFocusIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
	    
	    rqServicesIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
	    
		rqTheirMotivesStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		var rqDemandAreaStoreList = [
             {"value":"1","text":"50㎡以下"},
             {"value":"2","text":"50-70㎡"},
             {"value":"3","text":"70-90㎡"},
             {"value":"4","text":"90-120㎡"},
             {"value":"5","text":"120-140㎡"},
             {"value":"6","text":"140-160㎡"},
             {"value":"7","text":"160-180㎡"},
             {"value":"8","text":"180-200㎡"},
             {"value":"9","text":"200㎡以上"}
         ];
		var rqDemandAreaStore = Ext.data.Store({
		    	autoDestroy: true,
		        fields :["value","text"],
		        data : rqDemandAreaStoreList
		});
		
		var me=this;
		var row_1={
				fieldDefaults: {
		            labelAlign: 'top',
		            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
		            border: false,
		            xtype: 'panel',
		            flex: 1,
		            layout: 'anchor'
			    },
				layout: 'hbox',items: [{
		            items: [{
			            xtype:'combobox',  
			            id:'rqTheirMotives',  
			            store: rqTheirMotivesStore,
			            displayField: "codeName",           
			            valueField: "id", 
			            fieldLabel:'置业动机',
			            typeAhead: true,
		    			name:'rqTheirMotives',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }, {
			            xtype:'combobox',  
			            id:'rqDemandArea',  
			            store: rqDemandAreaStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'需求面积',
			            typeAhead: true,
		    			name:'rqDemandArea',
		                typeAhead:false, 
		                editable:false
		            },{
		            	xtype:'combobox',  
			            fieldLabel:'付款方式',  
			            typeAhead: true,
		    			name:'rqPaymentMethod',
		    			displayField: "des",           
				        valueField: "no", 
				        id:'rqPaymentMethod',
				        store:storeMethed(paymentMethod),
		                typeAhead:false, 
		                editable:false
		            }]
		        }, {
		            items: [{
			            xtype:'combobox',  
			            id:'rqFocusId',  
			            store: rqFocusIdStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'关注重点',
		    			name:'rqFocusId',
		    			triggerAction : 'all',
		                multiSelect : true,
		                queryMode:'local'
		            },{
			            xtype:'combobox',  
			            id:'rqServicesId',  
			            store: rqServicesIdStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'生活服务',
		    			name:'rqServicesId',
		                typeAhead:false, 
		                editable:false,
		                triggerAction : 'all',
		                multiSelect : true,
		                queryMode:'local'
		            }]
		        }]
	    };
		var columns3 = [{
			text : "组团名称",
			dataIndex : 'premisesId',
			width:'50%',
			editor: {
	            xtype:'combobox',  
	            id:'premisesId',  
	            store: premisesIdStore,
	            displayField: "groupName",
	            valueField: "id",
	            name:'premisesId',
	            queryMode:'local',
                typeAhead:false, 
                editable:false,
                listeners:{
	            	'change':function(value){
	            		roomIdStore.load({
	            			params:{
	            				'projectId':projectId,
	            				'premisesId':value.lastValue
	            			}
	            		});
	            	}
	            }
            },  
            renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
            	var index = premisesIdStore.find('id',value);  
                if(index!=-1){  
                    return premisesIdStore.getAt(index).data.groupName;  
                }  
                return value; 
            }
		},{
        	text:'操作',
        	xtype : 'actioncolumn',
        	width:'40%',
        	items:[{
        		 iconCls:'icon-delete',
        		 tooltip: '删除', 
        		 handler: function(grid, rowIndex, colIndex) {
        			 gridStore3.removeAt(rowIndex);
        		 }
        	}]
        }];
		var cellEditing3 = Ext.create('Ext.grid.plugin.CellEditing', {
	        clicksToEdit: 1
	    });
		var row_3=Ext.create('Ext.grid.Panel', {
			id:'yixiangGridPanel',
			title:"意向组团",
			minHeight:150,
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore3,
			columns : columns3,
			plugins: [cellEditing3],
			tbar:[{text:'新增',iconCls:'icon-add',
				handler:function(){
				    Ext.define('Record', { 
			            extend: 'Ext.data.Model', 
				    }); 
				    var record  = new Record(); 
				    gridStore3.insert(0, record);
				    cellEditing3.startEditByPosition({
				        row: 0, 
				    	column: 0
				    });
			}
			}
			]
		});
		var columns4 = [{
			text : "房间",
			dataIndex : 'roomId',
			width:'50%',
			editor: {
	            xtype:'combobox',  
	            id:'roomId',  
	            store: roomIdStore,
	            displayField: "combinedName",
	            valueField: "id",
	            name:'roomId',
	            queryMode:'local',
                typeAhead:false, 
                editable:false  
            },
		 renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
         	 var index = roomIdStore.find('id',value);  
             if(index!=-1){  
                 return roomIdStore.getAt(index).data.combinedName;  
             }  
             return value; 
         }
		},{
        	text:'操作',
        	xtype : 'actioncolumn',
        	width:'40%',
        	items:[{
        		 iconCls:'icon-delete',
        		 tooltip: '删除', 
        		 handler: function(grid, rowIndex, colIndex) {
        			 gridStore4.removeAt(rowIndex);
        		 }
        	}]
        }];
		var cellEditing4 = Ext.create('Ext.grid.plugin.CellEditing', {
	        clicksToEdit: 1
	    });
		var row_4=Ext.create('Ext.grid.Panel', {
			id:'fangyuanGridPanel',
			title:"意向房源",
			minHeight:150,
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore4,
			columns : columns4,
			plugins: [cellEditing4],
			tbar:[{text:'新增',iconCls:'icon-add',
				handler:function(){
				    Ext.define('Record', { 
			            extend: 'Ext.data.Model', 
				    }); 
				    var record  = new Record(); 
				    gridStore4.insert(0, record);
				    cellEditing4.startEditByPosition({
				        row: 0, 
				    	column: 0
				    });
				}
			}]
		});
		var row_5={
			defaults: {
	            border: false,
	            xtype: 'panel',
	            flex: 1
	        },
		    border: false,
			layout: 'hbox',
			items: [{
				items:row_3
			}, {
				items:row_4
			}]
	    };
		var items=[row_1,row_5];
		var initConfigg = {
		        title:"客户购房需求",
		        minHeight:220,
		        bodyStyle: 'padding:5px 5px 0',
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,
		            width:300
		        },
		        scrollable:true,
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

Ext.define('customer.payDeposit.add.membergePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		//省份
	    var peResidenceProvinceIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/provList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:true
	    });
	    //工作省
	    var peWorkaroundProvinceIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/provList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:true
	    });
	    //城市
	    var peResidenceCityIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/cityList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        }
	    });
	    //区域
	    var peResidenceAreaIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/areaList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        }
	    });
	    //工作城市
	    var peWorkaroundCityIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/cityList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        }
	    });
	    //工作区域
	    var peWorkaroundAreaIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/areaList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        }
	    });
	    
	    congshihangyeStore= new Ext.data.Store({
            singleton:true,
            autoDestroy:true,
            fields: ["id", "codeName"],
            proxy:{
                type:'ajax',
                url:contextPath+'/system/baseCodeValue/getCodeNameByType',
                reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
            },
            autoLoad:false
        });
	    
		var row_1={
				fieldDefaults: {
			            labelAlign: 'left',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',
				items: [{
		            items: [{
		            	items: [{
							xtype : "panel",
							layout : "hbox",
							border:false,
							items : [{
					            xtype:'combobox',  
					            id:'peResidenceProvinceId',  
					            store: peResidenceProvinceIdStore,
					            displayField: "areaName",           
					            valueField: "id",  
					            fieldLabel:'居住地',
				    			name:'peResidenceProvinceId' ,
					            typeAhead: true,
					            width:200,
					            listeners:{
					            	'select':function(value){
					            		Ext.getCmp('peResidenceCityId').setValue("");
					            		Ext.getCmp('peResidenceAreaId').setValue("");
						            		peResidenceCityIdStore.load({
						            			params:{
						            				'id':value.lastValue
						            			}
						            		});
					            	}
					            },
				                typeAhead:false, 
				                editable:false
				            },{
					            xtype:'combobox',  
					            id:'peResidenceCityId',  
					            store: peResidenceCityIdStore,
					            displayField: "areaName",           
					            valueField: "id",  
					            width:100,
				    			name:'peResidenceCityId' ,
					            typeAhead: true,
					            listeners:{
					            	'select':function(value){
					            		Ext.getCmp('peResidenceAreaId').setValue("");
					            			peResidenceAreaIdStore.load({
					            				params:{
					            					'id':value.lastValue
					            				}
					            			});
					            	}
					            },
				    			queryMode : 'local',
				                typeAhead:false, 
				                editable:false
				            },{
					            xtype:'combobox',  
					            id:'peResidenceAreaId',  
					            store: peResidenceAreaIdStore,
					            displayField: "areaName",           
					            valueField: "id",  
					            width:100,
					            typeAhead: true,
				    			name:'peResidenceAreaId',
				    			queryMode : 'local',
				                typeAhead:false, 
				                editable:false
				            }]
						}]
		            },{
		            	items: [{
		            		xtype : "container",
							layout : "hbox",
							items : [
								{
								    xtype:'combobox',  
								    id:'peWorkaroundProvinceId',  
								    store: peWorkaroundProvinceIdStore,
								    displayField: "areaName",           
								    valueField: "id",  
								    width:200,
								    fieldLabel:'工作区',
								    typeAhead: true,
								    listeners:{
								    	'select':function(value){
								    		Ext.getCmp('peWorkaroundCityId').setValue("");
								    		Ext.getCmp('peWorkaroundAreaId').setValue("");
								        		peWorkaroundCityIdStore.load({
								        			params:{
								        				'id':value.lastValue
								        			}
								        		});
								    	}
								    },
									name:'peWorkaroundProvinceId',
					                typeAhead:false, 
					                editable:false
								},{
								    xtype:'combobox',  
								    id:'peWorkaroundCityId',  
								    store: peWorkaroundCityIdStore,
								    displayField: "areaName",           
								    valueField: "id",  
								    width:100,
								    typeAhead: true,
								    listeners:{
								    	'select':function(value){
								    		Ext.getCmp('peWorkaroundAreaId').setValue("");
								        		peWorkaroundAreaIdStore.load({
								        			params:{
								        				'id':value.lastValue
								        			}
								        		});
								    	}
								    },
									name:'peWorkaroundCityId',
									queryMode : 'local',
					                typeAhead:false, 
					                editable:false
								},{
								    xtype:'combobox',  
								    id:'peWorkaroundAreaId',  
								    store: peWorkaroundAreaIdStore,
								    displayField: "areaName",           
								    valueField: "id",  
								    width:100,
								    typeAhead: true,
									name:'peWorkaroundAreaId',
									queryMode : 'local',
					                typeAhead:false, 
					                editable:false
								}
							]
		            	}]
		            }]
		        },{
		            items: [{
		            	 xtype:'combobox',
			             fieldLabel: '从事行业',
			             name: 'congshihangye',
			             id:'congshihangye',
			             displayField: "codeName",           
				         valueField: "id",  
				         store:congshihangyeStore,
			             typeAhead:false, 
			             editable:false,
			             queryMode:'local'
		            }]
		        }]
	    };
		var items=[row_1];
		var initConfigg = {
		        title:"客户个人信息",
		        minHeight:100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,
		            width:300
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

Ext.define('customer.payDeposit.addPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var estatePanel= Ext.create("customer.payDeposit.add.estatePanel");
		var customerPanel= Ext.create("customer.payDeposit.add.customerPanel");
		var firstjiePanel= Ext.create("customer.payDeposit.add.firstjiePanel");
		var membergePanel= Ext.create("customer.payDeposit.add.membergePanel");
		
		estatePanel.getForm().findField("customerPhone").setValue(customerPhone);
		// 首次接触时间不可编辑
        //firstjiePanel.getForm().findField("ftContactTimes").setValue(Ext.Date.format(new Date(),'Y-m-d'));

		var defaultConfigg = {
				buttonAlign:'center',
				id:'allFormPanel',
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true,  //可以折叠
		        },
		        renderTo:Ext.getBody(),
				items:[estatePanel,firstjiePanel,customerPanel,membergePanel],
				buttons:[
				         {xtype: "button",text: "保存",id:"customerSubmitBtn",iconCls:'icon-save',handler: function(){
				        	 var flag = true;
                             var projectSelect = Ext.getCmp('cbstore').getValue();
                             flag = verification(flag, projectSelect, "项目名称");
                         	 var customerStar = Ext.getCmp('customerStar').getValue();
                         	 flag = verification(flag, customerStar, "意向等级");
                         	 var customerName = Ext.getCmp('customerName').getValue();
                         	 flag = verification(flag, customerName, "客户姓名");
                         	 /*var customerStatus = Ext.getCmp('customerStatus').getValue();
                         	 flag = verification(flag, customerStatus, "客户状态");*/
                         	 var customerSex = Ext.getCmp('customerSex').getValue();
                         	 flag = verification(flag, customerSex, "性别");
                         	 /*var customerOrigin = Ext.getCmp('customerOrigin').getValue();
                         	 flag = verification(flag, customerOrigin, "客户性质");*/
                         	 var informedWay = Ext.getCmp('informedWay').getValue();
                         	 flag = verification(flag, informedWay, "获知途径");
                         	 var ftContactWay = Ext.getCmp('ftContactWay').getValue();
                         	 flag = verification(flag, ftContactWay, "接触方式");
                         	 var ftContactTimes = Ext.getCmp('ftContactTimes').getValue();
                         	 flag = verification(flag, ftContactTimes, "接触时间");
                         	 var ftContactContent = Ext.getCmp('ftContactContent').getValue();
                         	 flag = verification(flag, ftContactContent, "沟通内容");
		            		 var customerPhone = Ext.getCmp('customerPhone').getValue();
		            		 if(!customerPhone){
		            			 flag = verification(flag, customerPhone, "联系电话");
		            		 }else{
		            			//在验证手机号码是否正确
		            			Ext.Ajax.request({
		            				url: contextPath+'/common/mobile/verifyingMobile',
		            				params: {
		            					mobile: customerPhone,
		            				},
		            				method: 'POST',
		            				async: false,
		            				success: function(response){
		            					var text = Ext.decode(response.responseText);
		            					if(text.result=="1"){
		            						if(text.flag != "1"){
		            							Ext.MessageBox.alert('提示', '请输入正确的手机号码');
		            							flag=false;
			            						return;
		            						}
		            					}
		            				}
		            			});
		            			//判断手机号是否存在
		            			var projectId = Ext.getCmp('cbstore').getValue();
		            			Ext.Ajax.request({
		            				url: contextPath+'/customer/customer/customerPhone',
		            				params: {
		            					phone: customerPhone,
		            					projectId:projectId
		            				},
		            				method: 'POST',
		            				success: function(response){
		            					var text = Ext.decode(response.responseText);
		            					if(text.res=="1"){
		            						Ext.MessageBox.alert('提示', '该手机号码已存在!');
		            						flag=false;
		            						return;
		            					}else if(text.res=="10000"){
		            						Ext.MessageBox.alert("系统提示","系统异常!");
		            						flag=false;
		            						return;
		            					}
		            				}
		            			}); 
		            		}
							//校验是否可以提交
                            if(!flag){
                            	return false;
                            }
					     	var form = Ext.getCmp("allFormPanel").getForm();
				           	if(form.isValid()){
				           		var jsonArray=[];
				           		var jsonArray2=[];
				           		var jsonArray3=[];
				           		var jsonArray4=[];
				           		var resultJson="";
				           		var resultJson2="";
				           		var resultJson3="";
				           		var resultJson4="";
				           		//获得客户等级
				           		//意向户型
				           		var customerStar = Ext.getCmp('customerStar').getValue();
				           		if(customerStar=="1"||customerStar=="2"||customerStar=="3"){
						     		var records2=gridStore2.getCount();
						     		if(records2>0){
						     			for(var i=0;i<records2;i++){
							     			jsonArray2.push(Ext.JSON.encode(gridStore2.getAt(i).data));
							     		}
							     		 resultJson2=Ext.JSON.encode(jsonArray2);
						     		}
						     		
				           		}
				           		var records3=gridStore3.getCount();
				           		var records4=gridStore4.getCount();
				           		for(var i=0;i<records4;i++){
					     			jsonArray4.push(Ext.JSON.encode(gridStore4.getAt(i).data));
					     		}
					     	    resultJson4=Ext.JSON.encode(jsonArray4);
					     	    
					     		if(records3>0){
					     			for(var i=0;i<records3;i++){
						     			jsonArray3.push(Ext.JSON.encode(gridStore3.getAt(i).data));
						     		}
						     		 resultJson3=Ext.JSON.encode(jsonArray3);
					     		}
					     		var records=gridStore.getCount();
					     		if(records>0){
					     			for(var i=0;i<records;i++){
						     			jsonArray.push(Ext.JSON.encode(gridStore.getAt(i).data));
						     		}
						     		resultJson=Ext.JSON.encode(jsonArray);
					     		}
								//客户等级验证 2017.7.18
                                var level = validUserLevel();

                                var params = form.getValues();

                                params.isIntentionIntact = '1';
/**                          	自动判断客户等级需求
                                if(params.intentionLevel == 5){
                                	//20180525需求：当等级为D时，判断是否字段全部填写完毕，如填写完毕，则自动更改等级为C
									if(notBlank(CCouple)){
										params.intentionLevel = '4';//信息匹配意向等级
									}
                                    add(params,resultJson,resultJson2,resultJson3,resultJson4);
				           		}else if(level == -1){// 验证不通过
**/				           		
				           		if(level == -1){// 验证不通过
                                    if(params.intentionLevel === undefined || params.intentionLevel == null ||params.intentionLevel == ''){
                                        params.intentionLevel = realLevel();
									}
                                    layer.confirm('填写信息不全，不满足意向等级【'+levels[params.intentionLevel-1]+'】要求；',{
                                        btn:['我要保存','继续填写']
                                    },function(index){
                                        layer.close(index);
                                        layer.open({
                                            title:'客户信息完善',
                                            type: 1,
                                            area: ['450px', '300px'],
                                            shadeClose: true, //点击遮罩关闭
                                            content: '\<\div style="padding:5px;">填写信息不全，不满足意向等级【'+levels[params.intentionLevel-1]+'】要求；\<\/div>'+
                                            '\<\div style="margin:5px;"> 继续保存客户为意向等级【'+levels[params.intentionLevel-1]+'】；\<\/div>'+
                                            '\<\div style="margin:5px;"><span>备注：</span><textarea style="width: 400px;height: 100px;" id="remarkid" class="layui-layer-input"></textarea>\<\/div>',
                                            btn:['我要保存','按实际意向等级保存']
                                            ,yes:function(index){
                                                params.intentionLevelRemark = $("#remarkid").val();
                                                if(params.intentionLevelRemark == '' || params.intentionLevelRemark == null){
                                                    layer.tips('备注不能为空', '#remarkid');
                                                    return;
                                                }
                                                params.isIntentionIntact = '0';//信息不匹配意向登记
                                                add(params,resultJson,resultJson2,resultJson3,resultJson4);
                                                layer.close(index);
                                            },btn2:function(){
                                                //计算实际level
                                                params.intentionLevel = realLevel();
                                                add(params,resultJson,resultJson2,resultJson3,resultJson4);
                                            }});

                                    },function(index){
                                        layer.close(index);
                                    })
                                }else if(level == 0){//验证通过
                                    add(params,resultJson,resultJson2,resultJson3,resultJson4);
                                    
                                /**自动判断客户等级需求（使用时需要去掉以下代码）start**/
                                }else{//自动判断意向等级()
                                    //params.intentionLevel = realLevel();
                                    //若意向等级为5的判断 是否满足字段
									if(params.intentionLevel == '5'){
										if(notBlank(DCouple)){
											params.isIntentionIntact = '4';//信息匹配意向等级
										}else{
											params.isIntentionIntact = '0';//信息不匹配意向等级
										}
                                    }
                                    add(params,resultJson,resultJson2,resultJson3,resultJson4);
                                    /**end**/
                                }

// 					     		if(flag){
// 					     			Ext.getCmp("customerSubmitBtn").setVisible(false);
// 					     			Ext.Ajax.request({
// 					     				url: contextPath+'/customer/customer/add?gridJson='+resultJson+'&gridJson2='+resultJson2+'&gridJson3='+resultJson3+'&gridJson4='+resultJson4,
// 					     				params:form.getValues(),
// 					     				callback: function (options, success, response) {
// 					     					 if (success) {
// 					     						 var obj = JSON.parse(response.responseText);
// 					     						 if(obj.res=="1"){
// 					     							Ext.MessageBox.alert("系统提示","保存成功");
// 					     							setTimeout(function(){
// 					     								location.href=contextPath+'/customer/customer/index?menu=menu_0006_0001';
// 					     								//location.href=contextPath + "/customer/customer/toDetail?customerId="+obj.obj+"&resourcesCode=menu_0006_0001";
// 					     							}, 2000)
// //					     							Ext.getCmp("save_button").setVisible(false);
// 					     						 }else{
// 					     							Ext.getCmp("customerSubmitBtn").setVisible(true);
// 					     							 Ext.MessageBox.alert("系统提示",obj.resMsg);
// 					     						 }
// 					     		        	 }else{
// 					     		        		Ext.getCmp("customerSubmitBtn").setVisible(true);
// 					     		        		 Ext.MessageBox.alert("系统提示","系统异常!");
// 					     		        	 }
// 					     				}
//
// 					     			});
// 					     		}
					        	 
					         }
				         }
				         },
//				         {xtype: "button",text: "提交审核",iconCls:'icon-save',handler: function(){
//				        	 
//				         }},
				         {xtype: "button",text: "返回",iconCls:'icon-save',handler: function(){
				        	 var tabKey = "customer_"+defaultProjectId;
				        	 parent.TabControlRemove(tabKey);
				         }}
				]
		};
		Ext.apply(this,defaultConfigg);
		this.callParent(arguments);
	}
});
/**
 * 验证必填字段字段
 * @param flag为上一个字段的校验结果，当上一个校验结果未通过时，不用进行下一个字段校验，直接返回false
 * @param value 字段值
 * @param name 字段名称
 * @returns
 */
function verification(flag, value, name){
	if(flag && !value){
		//当flag为true，并且value为空时提示
		var content = '\<span\ style="color:#c00">请填写“'+name+'”\<\/span\>';
		tips(content);
        return false
    }else if(flag && value){
    	//flag为true，并且value不为空时，返回验证通过
    	if(name == "客户姓名"){
    		if(value.length > 30){
    			var content = '\<span\ style="color:#c00">“'+name+'”最多30个字，当前'+value.length+'个字\<\/span\>';
    			tips(content);
    			return false;
    		}
    	}
    	return true;
    }
	//否则返回不通过
	return false;
}
function tips(content){
    layer.open({
        title:'客户信息完善',
        content: content,
        btn:'继续填写',
        yes:function(index){
            layer.close(index);
        }
    });
}
/**
 * 校验是否可以填写“电转访”
 */
/*function callToVisit(flag){
	//当选择“电转访”时，判断是否填写来电，如没填写，则禁用“电转访”字段
	if(Ext.getCmp("ftContactWay1").rawValue != "电转访"){
		Ext.getCmp("ftContactTimes1").setReadOnly(false);
		Ext.getCmp("ftContactContent1").setReadOnly(false);
		return false;
	}
	if(!Ext.getCmp("ftContactTimes").getValue() 
			|| !Ext.getCmp("ftContactContent").getValue().trim()){
		//当使用下拉框选择“电转访”时，弹出提示
		if(flag == "T"){
			Ext.MessageBox.alert('提示', '请先填写完来电信息后再填写电转访信息');
		}
		//清空字段，并设为只读
		Ext.getCmp("ftContactTimes1").setValue("");
		Ext.getCmp("ftContactTimes1").setReadOnly(true);
		Ext.getCmp("ftContactContent1").setValue("");
		Ext.getCmp("ftContactContent1").setReadOnly(true);
	}else{
		Ext.getCmp("ftContactTimes1").setReadOnly(false);
		Ext.getCmp("ftContactContent1").setReadOnly(false);
	}
}*/
/**
 * 校验是否填写首次接触信息
 */
/*function contactWay(flag){
	//当之前的校验未通过时，不进行接触方式校验
	if(!flag){
		return false;
	}
	//来访/电转访下拉框
	var ftContactWay1 = Ext.getCmp("ftContactWay1").rawValue;
	//来电 接触时间
	var ftContactTimes = Ext.getCmp("ftContactTimes").getValue();
	//来电 沟通内容
	var ftContactContent = Ext.getCmp("ftContactContent").getValue();
	//来访/电转 接触时间
	var ftContactTimes1 = Ext.getCmp("ftContactTimes1").getValue();
	//来访/电转 沟通内容
	var ftContactContent1 = Ext.getCmp("ftContactContent1").getValue();
	
	if(ftContactWay1 == "电转访"){
		//判断来电信息是否填写
		if(!ftContactTimes || !ftContactContent){
			verification(true, null, "首次来电信息");
			return false;
		}
	}
	//判断来电或来访信息是否填写
	if((!ftContactTimes || !ftContactContent) 
			&& (!ftContactTimes1 || !ftContactContent1)){
		verification(true, null, "首次来电信息”或“来访信息");
		return false;
	}else if((!ftContactTimes || !ftContactContent) && !ftContactWay1){
		verification(true, null, "首次来电信息”或“来访信息");
		return false;
	}else if(!ftContactTimes || !ftContactContent){
		//未填写首次来电时，清空首次来电选项
		Ext.getCmp('ftContactWay').setValue("");
	}else if(!ftContactTimes1 || !ftContactContent1){
		//未填写首次来访/电转访时，清空首次来访/电转访选项
		Ext.getCmp('ftContactWay1').setValue("");
	}
	return true;
}*/
